<template>
  <div class="app-container">
    <FormDialog v-model="visible" :taskStatus="G.TASK_STATUS.APPROVAL"
                @previewFormVisible="(val)=>formVisible=val" :taskId="taskId"/>
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="流程定义" prop="processDefinitionId">
        <el-input
            v-model="queryParams.processDefinitionId"
            placeholder="请输入流程定义"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="流程实例ID" prop="processInstancesId">
        <el-input
            v-model="queryParams.processInstancesId"
            placeholder="请输入流程实例ID"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="流程节点" prop="processDesignId">
        <el-input
            v-model="queryParams.processDesignId"
            placeholder="请输入流程节点"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处理人" prop="APPROVER">
        <el-input
            v-model="queryParams.APPROVER"
            placeholder="请输入处理人"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人" prop="createBy">
        <el-input
            v-model="queryParams.createBy"
            placeholder="请输入创建人"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable
                        v-model="queryParams.createTime"
                        type="date"
                        value-format="YYYY-MM-DD"
                        placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新人" prop="updateBy">
        <el-input
            v-model="queryParams.updateBy"
            placeholder="请输入更新人"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="updateTime">
        <el-date-picker clearable
                        v-model="queryParams.updateTime"
                        type="date"
                        value-format="YYYY-MM-DD"
                        placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table header-cell-class-name="custom-header-cell" v-loading="loading" :data="taskList">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="任务ID" align="center" prop="ID"/>
      <el-table-column label="流程定义" align="center" prop="processDefinitionId"/>
      <el-table-column label="流程实例ID" align="center" prop="processInstancesId"/>
      <el-table-column label="流程节点" align="center" prop="processDesignId"/>
      <TaskStatusColumn/>
      <el-table-column label="任务类型 1 发起人任务 2 审批人任务 3 抄送人任务 4 转交人任务" align="center"
                       prop="taskType">
        <template #default="scope">
          <el-tag type="success" v-if="scope.row.taskType == G.TASK_TYPE.INITIATOR_TASK" size="small">
            {{ G.TASK_TYPE_NAME.INITIATOR_TASK }}
          </el-tag>
          <el-tag type="warning" v-if="scope.row.taskType == G.TASK_TYPE.APPROVER_TASK" size="small">
            {{ G.TASK_TYPE_NAME.APPROVER_TASK }}
          </el-tag>
          <el-tag type="info" v-if="scope.row.taskType == G.TASK_TYPE.CC_TASK" size="small">
            {{ G.TASK_TYPE_NAME.CC_TASK }}
          </el-tag>
          <el-tag type="info" v-if="scope.row.taskType == G.TASK_TYPE.TRANSFER_TASK" size="small">
            {{ G.TASK_TYPE_NAME.TRANSFER_TASK }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="当前处理人" align="center" prop="approverName">
        <template #default="scope">
          {{ scope.row.approverName }}
          <el-divider direction="vertical"></el-divider>
          {{ scope.row.approver }}
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createBy"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template #default="scope">
            <span>{{
                parseTime(scope.row.createTime,
                    '{y}-{m}-{d}')
              }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updateBy"/>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template #default="scope">
            <span>{{
                parseTime(scope.row.updateTime,
                    '{y}-{m}-{d}')
              }}</span>
        </template>
      </el-table-column>
      <el-table-column width="150" label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button @click="enterTask(scope)" type="primary" link icon="Position">
            进入流程
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />
  </div>
</template>
<script setup name="Todo">
import {
  getTodoList,
  getTaskDetail
} from "@/api/flow/task";
import FormDialog from "@/views/flow/createDirectly/generatorForm/FormDialog/index.vue";
import moment from "moment";
import TaskStatusColumn from "@/components/EbComponent/TableColumn/TaskStatusColumn.vue";
const {proxy} = getCurrentInstance();
const taskList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const visible = ref(false);
const total = ref(0);
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    dingtalkTaskId: null,
    dingtalkMsgId: null,
    processDefinitionId: null,
    processInstancesId: null,
    processDesignId: null,
    APPROVER: null,
    originalApprover: null,
    TRANSFEROR: null,
    preTaskId: null,
    fromBackTaskId: null,
    fromTransferTaskId: null,
    fromInformedTaskId: null,
    fromWithdrawTaskId: null,
    taskType: null,
    taskStatus: null,
    approvalMethod: null,
    INFORMED: null,
    CIRCULATE: null,
    READ: null,
    RESTART: null,
    RELOCATION: null,
    AUTO: null,
    takeMsg: null,
    REMARK: null,
    createBy: null,
    createTime: moment()
        .format("YYYY-MM-DD"),
    updateBy: null,
    updateTime: null
  },
  rules: {}
});
const {
  queryParams,
  form,
  rules
} = toRefs(data);
const taskId = ref(undefined)
const enterTask = ({row}) => {
  taskId.value = row.ID
  visible.value = true
}
/** 查询流程任务列表 */
function getList() {
  loading.value = true;
  getTodoList({...queryParams.value})
      .then(response => {
        taskList.value = response.rows;
        total.value = parseInt(response.total);
        loading.value = false;
      });
}
// 表单重置
function reset() {
  form.value = {
    ID: null,
    dingtalkTaskId: null,
    dingtalkMsgId: null,
    processDefinitionId: null,
    processInstancesId: null,
    processDesignId: null,
    APPROVER: null,
    originalApprover: null,
    TRANSFEROR: null,
    preTaskId: null,
    fromBackTaskId: null,
    fromTransferTaskId: null,
    fromInformedTaskId: null,
    fromWithdrawTaskId: null,
    taskType: null,
    taskStatus: null,
    approvalMethod: null,
    INFORMED: null,
    CIRCULATE: null,
    READ: null,
    RESTART: null,
    RELOCATION: null,
    AUTO: null,
    takeMsg: null,
    REMARK: null,
    createBy: null,
    createTime: moment()
        .format("YYYY-MM-DD"),
    updateBy: null,
    updateTime: null
  };
  proxy.resetForm("taskRef");
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}
getList();
const success = (res) => {
}
</script>
<style scoped lang="scss">
:deep(.custom-header-cell) {
  vertical-align: top;
  .cell {
  }
}
</style>
